package com.ronds.webtest.util;

import org.openqa.selenium.support.PageFactory;

import static com.ronds.webtest.util.WebDriverManager.getDriver;
import static com.ronds.webtest.util.WebElementUtil.getCurrentUrl;
import static com.ronds.webtest.util.WebElementUtil.sleep;

/**
 * Created by zhanghui on 2017/2/8.
 */
public class PageManager {

    public static <T> T getPage(String url, Class T) {
        navigateTo(url);
        return (T)PageFactory.initElements(getDriver(), T);
    }

    public static void navigateTo(String url) {
        if(url !=null && !getCurrentUrl().equals(ConfigUtil.getBaseUrl() + url)) {
            getDriver().get(ConfigUtil.getBaseUrl() + url);
            sleep(1);
        }
    }

}